using System.Collections;
using System.Collections.Generic;
using Holoville.HOTween;
using Holoville.HOTween.Core;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameTopWindow : BaseWindow
{
	public static GameTopWindow instance;

	public MissionHUD missionHud;

	public LeaderHUD leaderHud;

	public UIPanel policeWarning;

	public UIPanel aggressiveLabel;

	public GameObject aggressiveWarningLabel;

	public GameObject aggressiveDangerLabel;

	public GameObject panelLevel;

	public GameObject freezePanel;

	public GameObject stunPanel;

	public GameObject electroPanel;

	public GameObject indicatorTimeGame;

	public GameObject indicatorPoints;

	public GameObject lbInfo;

	public GameObject butChat;

	public GameObject indicatorPVP;

	public GameObject messageWait;

	public GameObject indicatorIamWinner;

	public GameObject healtsIcon;

	public UILabel lbTextTutorial;

	public UILabel lbTextTutorialTony;

	public UILabel lbWarning;

	public UISprite sprEndTutor;

	public UIButton buttonCallCar;

	public GameObject buttonGetInCar;

	public UISprite sprIndicator;

	[SerializeField]
	private GameObject leaderBoardButton;

	public UILabel lbTimeGame;

	public UILabel lbPoints;

	public UILabel lbMessage1;

	public UILabel lbMessage2;

	public UILabel lbMessage3;

	public UILabel lbMessage21;

	public UILabel lbMessage22;

	public UILabel lbMessage23;

	public UILabel lbTimePVP;

	public UILabel lbKillPVP;

	public GameObject pvpTime;

	public GameObject pvpKills;

	public StatsManager statsManager;

	public GameObject panelAchievement;

	private clearMessage lbClaer1;

	private clearMessage lbClaer2;

	private clearMessage lbClaer3;

	private clearMessage lbClaer21;

	private clearMessage lbClaer22;

	private clearMessage lbClaer23;

	private TweenAlpha twAlpha;

	public UILabel timerCopsAndRobert;

	public GameObject timerObjectCopsAndRobert;

	private float timeForNextMsg;

	private List<string> listMsgForPlayer = new List<string>();

	[HideInInspector]
	public List<string> listMessages = new List<string>();

	public List<string> secondChatlistMessages = new List<string>();

	public DeathMessage deathMessagePanel;

	public GameObject leaderboard;

	public PvPLeaderbord pvpLeaderboard;

	[SerializeField]
	private GameObject leaderIcon;

	public bool isDeath
	{
		set
		{
			if (!(deathMessagePanel == null))
			{
				if (value)
				{
					deathMessagePanel.Show();
				}
				else
				{
					deathMessagePanel.Hide();
				}
			}
		}
	}

	public bool IamWinnerActive
	{
		set
		{
			if (indicatorIamWinner != null)
			{
				indicatorIamWinner.SetActive(value);
			}
		}
	}

	public int Points
	{
		set
		{
			lbPoints.text = string.Empty + value;
		}
	}

	private void Awake()
	{
		instance = this;
		if (indicatorPoints != null)
		{
			indicatorPoints.SetActive(false);
		}
		if (indicatorTimeGame != null)
		{
			indicatorTimeGame.SetActive(false);
		}
		if (freezePanel != null)
		{
			freezePanel.SetActive(false);
		}
		if (GameController.instance.curTypeGame == TypeGame.race)
		{
			butChat.SetActive(false);
		}
		if (TDMController.isTeamGameType && GameController.instance.curTypeGame != TypeGame.CopsAndRobbers)
		{
			pvpTime.transform.localPosition = new Vector3(60f, 283f, 0f);
			leaderBoardButton.SetActive(false);
		}
		leaderboard.SetActive(true);
		settings.gameModeChange += HideAggressiveLabel;
		settings.gameModeChange += HidePoliceWarning;
	}

	public void StartInit()
	{
		lbPoints.text = "0";
		lbMessage1.text = string.Empty;
		lbMessage2.text = string.Empty;
		lbMessage3.text = string.Empty;
		lbMessage21.text = string.Empty;
		lbMessage22.text = string.Empty;
		lbMessage23.text = string.Empty;
		lbClaer1 = lbMessage1.GetComponent<clearMessage>();
		lbClaer2 = lbMessage2.GetComponent<clearMessage>();
		lbClaer3 = lbMessage3.GetComponent<clearMessage>();
		lbClaer21 = lbMessage21.GetComponent<clearMessage>();
		lbClaer22 = lbMessage22.GetComponent<clearMessage>();
		lbClaer23 = lbMessage23.GetComponent<clearMessage>();
		if (settings.offlineMode)
		{
			butChat.SetActive(false);
			indicatorPVP.SetActive(false);
			pvpTime.SetActive(false);
			pvpKills.SetActive(false);
			return;
		}
		indicatorPVP.SetActive(true);
		if (GameController.instance.curTypeGame == TypeGame.race)
		{
			indicatorPVP.SetActive(false);
			butChat.SetActive(false);
		}
		if (!SceneManager.GetActiveScene().name.Equals("Level1") && !SceneManager.GetActiveScene().name.Equals("Level1_Offline"))
		{
			pvpTime.SetActive(false);
		}
		else
		{
			pvpTime.SetActive(false);
		}
		if (TDMController.isTeamGameType && GameController.instance.curTypeGame != TypeGame.CopsAndRobbers)
		{
			pvpTime.SetActive(true);
		}
		pvpKills.SetActive(false);
	}

	private void Start()
	{
		StartInit();
		if (GameController.instance.curTypeGame != TypeGame.CopsAndRobbers)
		{
			pvpTime.SetActive(false);
		}
		InGameTutorial.StartTutorial("new_tutorial", base.transform.parent, string.Empty);
	}

	private void OnDestroy()
	{
		instance = null;
		settings.gameModeChange -= HideAggressiveLabel;
		settings.gameModeChange -= HidePoliceWarning;
	}

	private void OnEnable()
	{
	}

	private void OnDisable()
	{
	}

	public void ToggleAggressiveLabel()
	{
		if (policeWarning.alpha != 0f || (MobSpawnController.instance.aggressiveMobsCount < 1 && !MobSpawnController.instance.globalAgrState) || SceneManager.GetActiveScene().name == "Tutorial")
		{
			aggressiveLabel.gameObject.SetActive(false);
			return;
		}
		aggressiveLabel.gameObject.SetActive(true);
		if (MobSpawnController.instance.globalAgrState)
		{
			aggressiveWarningLabel.SetActive(false);
			aggressiveDangerLabel.SetActive(true);
		}
		else
		{
			aggressiveWarningLabel.SetActive(true);
			aggressiveDangerLabel.SetActive(false);
		}
	}

	public void HideAggressiveLabel()
	{
		aggressiveLabel.gameObject.SetActive(false);
	}

	public void HidePoliceWarning()
	{
		if (PoliceManager.Instance != null)
		{
			PoliceManager.Instance.StopChasing();
			aggressiveLabel.gameObject.SetActive(false);
		}
	}

	private void ShowMsgNeedBuy(int weaponInd)
	{
		listMsgForPlayer.Add("buy ammo");
	}

	private void ShowNextMsgForPlayer()
	{
		if (listMsgForPlayer.Count > 0 && !(timeForNextMsg <= 0f))
		{
		}
	}

	public override void OnPreShow(object userData)
	{
		if (GameController.instance.playerScript != null && settings.learningCompleted)
		{
			if (GameController.instance.playerScript.inHelic)
			{
				WindowManager.instance.ShowWindow(typeof(FlyWindow), false);
			}
			else if (GameController.instance.playerScript.inCar)
			{
				WindowManager.instance.ShowWindow(typeof(CarWindow), false);
			}
			else
			{
				WindowManager.instance.ShowWindow(typeof(WalkWindow), false);
			}
		}
		if (settings.learningCompleted && GameController.instance.curTypeGame != TypeGame.RocketLeague && GameController.instance.curTypeGame != TypeGame.SkyBlock && GameController.instance.curTypeGame != TypeGame.CopsAndRobbers)
		{
			if (MapWindow.instance != null)
			{
				MapWindow.instance.panelMiniMap.gameObject.SetActive(true);
				MapWindow.HideWorldMap();
			}
			WindowManager.instance.ShowWindow(typeof(MapWindow), false);
		}
		else if (MapWindow.instance != null && MapWindow.instance.panelMiniMap != null)
		{
			MapWindow.instance.panelMiniMap.gameObject.SetActive(false);
		}
		if (WalkWindow.instance.panelJoystick != null)
		{
			WalkWindow.instance.panelJoystick.gameObject.SetActive(true);
		}
		SetActiveIndictorExp(true);
		HitMarks.instance.gameObject.SetActive(true);
		rednessScreen.inst.gameObject.SetActive(true);
		MessageWindow.instance.SetVisiblePanelLoading(false, string.Empty);
		if (TrackArrowController.instance != null)
		{
			TrackArrowController.instance.SetActivCamera(true);
		}
	}

	public override void OnShow(object userData)
	{
		MessageManager.instance.SetActivate(true);
	}

	public override void OnHide()
	{
		SetActiveIndictorExp(false);
		MessageManager.instance.SetActivate(false);
		if (TrackArrowController.instance != null)
		{
			TrackArrowController.instance.SetActivCamera(false);
		}
	}

	public void ShowLeaderIcon(bool imLeader)
	{
		leaderIcon.SetActive(imLeader);
	}

	public void SetLeader(PlayerBehavior _leader)
	{
		leaderHud.NewLeader(_leader);
	}

	public void updateLbTimeGame()
	{
		int num = (int)(GameController.instance.timeGame / 60f);
		int num2 = (int)(GameController.instance.timeGame - (float)(num * 60));
		string text = ((num2 >= 10) ? string.Empty : "0");
		lbTimeGame.text = string.Empty + num + ":" + text + num2;
	}

	public void AddAndShowNextMessage(string msg, int chatIndex = 0)
	{
		if (chatIndex == 0)
		{
			listMessages.Add(msg);
		}
		else
		{
			secondChatlistMessages.Add(msg);
		}
		showNextMessageFromList(chatIndex);
	}

	public void SetArmorValue(int value, int maxValue)
	{
		statsManager.maxArmor = maxValue;
		statsManager.armor = value;
	}

	public void SetHealthValue(int value, int maxValue)
	{
		statsManager.maxHealth = maxValue;
		statsManager.health = value;
	}

	public void SwitchHealthBarToEntity(bool value)
	{
		if (!PlayerBehavior.MyPlayer.inCar || value)
		{
			statsManager.SwitchHealthBarToEntity(value);
		}
	}

	public void HideAllHealth()
	{
		statsManager.DisableAllHealthBars();
	}

	public void SetEntityHealth(int value, int maxValue)
	{
		statsManager.maxEntityHealth = maxValue;
		statsManager.entityHealth = value;
	}

	public void SetExperienceValue(int value, int maxValue)
	{
		statsManager.maxExperience = maxValue;
		statsManager.experience = value;
	}

	public void SetLvLValue(int value)
	{
		statsManager.lvl = value;
	}

	public void showNextMessageFromList(int chatIndex)
	{
		if (chatIndex == 0 && listMessages.Count > 0)
		{
			lbMessage3.text = lbMessage2.text;
			lbMessage2.text = lbMessage1.text;
			lbMessage1.text = listMessages[0];
			if (lbClaer3 != null && lbClaer2 != null)
			{
				lbClaer3.start(lbClaer2.timeForClear);
			}
			if (lbClaer2 != null && lbClaer1 != null)
			{
				lbClaer2.start(lbClaer1.timeForClear);
				lbClaer1.start(5f);
			}
			listMessages.RemoveAt(0);
		}
		else if (chatIndex == 1 && secondChatlistMessages.Count > 0)
		{
			Debug.Log("Show message");
			lbMessage23.text = lbMessage22.text;
			lbMessage22.text = lbMessage21.text;
			lbMessage21.text = secondChatlistMessages[0];
			if (lbClaer23 != null && lbClaer22 != null)
			{
				lbClaer3.start(lbClaer2.timeForClear);
			}
			if (lbClaer22 != null && lbClaer21 != null)
			{
				lbClaer22.start(lbClaer1.timeForClear);
				lbClaer21.start(5f);
			}
			secondChatlistMessages.RemoveAt(0);
		}
	}

	public void SetActiveIndictorExp(bool val)
	{
		if (panelLevel != null)
		{
			panelLevel.SetActive(val);
		}
	}

	public void ShowMessages(string val)
	{
		lbWarning.text = val;
		if (!IsInvoking("HideMessages"))
		{
			Invoke("HideMessages", 2f);
			lbWarning.gameObject.SetActive(true);
			twAlpha = TweenAlpha.Begin(lbWarning.gameObject, 0.4f, 1f);
			twAlpha.from = 0.5f;
			twAlpha.to = 1f;
			twAlpha.style = UITweener.Style.PingPong;
		}
	}

	private void HideMessages()
	{
		Object.Destroy(twAlpha);
		lbWarning.gameObject.SetActive(false);
	}

	public IEnumerator BonusAnimation(GameObject obj)
	{
		GameObject obj2 = default(GameObject);
		HOTween.To(obj.transform, 0.35f, new TweenParms().Prop("localScale", new Vector3(1.25f, 1.25f, 1.25f)).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			HOTween.To(obj2.transform, 0.2f, new TweenParms().Prop("localScale", new Vector3(1f, 1f, 1f)));
		}));
		yield return null;
	}

	public IEnumerator BonusAnimation(List<GameObject> objList)
	{
		foreach (GameObject obj in objList)
		{
			StartCoroutine(BonusAnimation(obj));
		}
		yield return null;
	}
}
